{template 'common/header'}
<script>
    $(function(){
        var finish = "{$finish['id']}";
        if(finish > 0){
            alert("当日订单已经完成!");
        }
        $("#day").on('change',function(){
            var day = $(this).val();
            var url = "{php echo $this->createWebUrl('orders',array('op' => 'check_finish'))}";
            $.ajax({
                type : 'post',
                url : url,
                data : {'day' : day},
                success : function(data){
                    if(data == 111){
                        alert("该天订单已经完成！");
                    }
                }
            });
        });
        $("#key-word").focus();
        $(".key-word").keyup(function(){
            var key_word = $(this).val();
            var region_id = $(".region").val();
            var url = "{php echo $this->createWebUrl('express',array('op' => 'find_member'))}";
            $.ajax({
                type : 'post',
                url : url,
                data : {'key_word' : key_word, 'region_id' : region_id},
                success : function(data){
                    $("#member-list").html(data);
                }
            });
        });
        $(".region").change(function(){
            var region_id = $(this).val();
            var key_word = $("#key-word").val();
            var order_region = $("#order-region").val();
            location.href = "{php echo $this->createWebUrl('express',array('op' => 'add'))}&region_id="+region_id+"&key_word="+key_word+"&order_region="+order_region;
        });
        $(".order-region").change(function(){
            var region_id = $(this).val();
            var url = "{php echo $this->createWebUrl('express',array('op' => 'save_server_id'))}";
            $.ajax({
                type : 'post',
                url : url,
                data : {'server_id' : region_id},
                success : function(data){
                    location.reload();
//                    alert(data);
                }
            });
//            location.href = "{php echo $this->createWebUrl('express',array('op' => 'add'))}&region_id="+region_id+"&key_word="+key_word+"&order_region="+order_region;
        });
        $("#company_id").on('change',function(){
            var company_id = $("#company_id").val();
            var url = "{php echo $this->createWebUrl('express',array('op' => 'save_company'))}";
            $.ajax({
                type : 'post',
                url : url,
                data : {'company_id' : company_id},
                success : function(){

                }
            });
        });
        $(".choose-member").click(function(){
            var member_id = $(this).attr("member_id");
            var day = $("#day").val();
            var company_id = $("#company_id").val();
            var server_id = $("#server_id").val();
            if(member_id > 0){
                location.href="{php echo $this->createWebUrl('express',array('op' => 'add_order'))}&member_id="+member_id+"&day="+day+"&company_id="+company_id+"&server_id="+server_id;
            }
        });
    });
    function choose_member(member_id){
        var day = $("#day").val();
        var company_id = $("#company_id").val();
        var server_id = $("#server_id").val();
        if(member_id > 0) {
            location.href="{php echo $this->createWebUrl('express',array('op' => 'add_order'))}&member_id="+member_id+"&day="+day+"&company_id="+company_id+"&server_id="+server_id;
        }
    }
</script>
<ul class="nav nav-tabs">
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'order_list'))}">快递订单</a></li>
    <li class="active"><a href="{php echo $this->createWebUrl('express', array('op'=>'add'))}">添加订单</a></li>
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'company'))}">快递公司管理</a></li>
    <li ><a href="{php echo $this->createWebUrl('express', array('op'=>'server'))}">服务社管理</a></li>
</ul>
<div class="main">
    <!--<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">-->
    <div class="panel panel-default">
        <div class="panel-heading">
            新增订单
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col-xs-2">搜索客户</div>
                <div class="col-xs-2">订单日期</div>
                <div class="col-xs-2">客户区域</div>
                <div class="col-xs-2">快递公司</div>
                <div class="col-xs-3">服务社（不选默认客户所在区域服务社）</div>
            </div>
            <div class="row">
                <div class="col-xs-2"><input type="text" value="{$key_word}" placeholder="客户名称/简称/电话" class="form-control key-word" id="key-word" /></div>
                <div class="col-xs-2">
                    <input style="color:red;" type="date" value="{$day}" class="form-control" id="day" />
                </div>
                <div class="col-xs-2">
                    <select class="form-control region" id="region-id">
                        <option>请选择区域</option>
                        {loop $regions $region}
                        <option value="{$region['id']}" {if $region['id'] == $region_id} selected='selected' {/if}>{$region['name']}</option>
                        {/loop}
                    </select>
                </div>
                <div class="col-xs-2">
                    <select class="form-control" id="company_id">
                        <option value="0">快递公司</option>
                        {loop $companys $company}
                        <option value="{$company['id']}" {if $company_id == $company['id']} selected="selected" {/if}>{$company['name']}</option>
                        {/loop}
                    </select>
                </div>
                <div class="col-xs-3">
                    <select class="form-control order-region" id="server_id">
                        <option value="0">请选择服务社</option>
                        {loop $servers $server}
                        <option value="{$server['id']}" {if $server['id'] == $server_id} selected="selected" {/if}>{$server['name']}</option>
                        {/loop}
                    </select>
                </div>
            </div>
            <br />
            <div class="row" style="padding-left: 10px;">
                <a href="{php echo $this->createWebUrl('members',array('op' => 'add','order_add' => 1,'express' => 1))}">
                    <button class="btn btn-primary">新增客户</button>
                </a>
                <!--<button class="btn btn-warning" data-toggle="modal" data-target="#myModal">新增一次性客户</button>-->
            </div>
            <br />
            <div>
                <table class="table" id="member-list">
                    <tr >
                        <th>编号</th>
                        <th>客户名称</th>
                        <th>客户电话</th>
                        <th>客户区域</th>
                        <th>备注</th>
                    </tr>
                    {loop $list $l}
                    <tr class="member" member_id="{$l['id']}">
                        <td>
                            {$l['key']}
                        </td>
                        <td>
                            <button class="btn btn-primary choose-member" member_id="{$l['id']}">{$l['name']}</button>
                        </td>
                        <td>{$l['phone']}</td>
                        <td>{$l['region']}</td>
                        <td>{$l['remark']}</td>
                    </tr>
                    {/loop}
                </table>
            </div>

        </div>
    </div>
</div>




{template 'common/footer'}